package com.googlecode.wicketcharts.highcharts.gson;

import java.lang.reflect.Type;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.googlecode.wicketcharts.highcharts.options.PixelOrPercent;
import com.googlecode.wicketcharts.highcharts.options.PixelOrPercent.Unit;

/**
 * Serializer for the {@link PixelOrPercent} class.
 * 
 * @author Tom Hombergs (tom.hombergs@gmail.com)
 * 
 */
public class GsonPixelOrPercentSerializer implements
		JsonSerializer<PixelOrPercent> {

	@Override
	public JsonElement serialize(PixelOrPercent src, Type typeOfSrc,
			JsonSerializationContext context) {
		

		if (src.getUnit() == Unit.PERCENT) {
			String value = String.valueOf(src.getValue()) + "%";
			return new JsonPrimitive(value);
		}else{
			return new JsonPrimitive(src.getValue());
		}

	}
}
